package com.lewis.spider;

import java.io.File;
import java.io.IOException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

import org.w3c.dom.Document;
import org.xml.sax.SAXException;

public class TestXSLT {
	public static void main(String[] args) throws ParserConfigurationException {
		  // TODO 自动生成方法存根
		  DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
		  try
		  {
		   DocumentBuilder db=dbf.newDocumentBuilder();
		   Document doc=db.parse("/Users/henrylian/Documents/workspace/lewis-parent/http-request-pilot/src/main/resources/com/lewis/spider/web/data.xml");
		   DOMSource source=new DOMSource(doc);
		   StreamResult result=new StreamResult(new File("/Users/henrylian/Documents/workspace/lewis-parent/http-request-pilot/src/main/resources/com/lewis/spider/web/xslttest.html"));
		            StreamSource ss=new StreamSource(new File("/Users/henrylian/Documents/workspace/lewis-parent/http-request-pilot/src/main/resources/com/lewis/spider/web/xslt.xsl"));
		            TransformerFactory tff = TransformerFactory.newInstance();
		            Transformer tf = tff.newTransformer(ss);
		            tf.setOutputProperty("encoding", "GBK");
		            tf.transform(source, result);
		  }
		        catch(ParserConfigurationException e){e.printStackTrace();}
		        catch(SAXException e){e.printStackTrace();}
		        catch(IOException e){e.printStackTrace();}
		        catch(TransformerConfigurationException e){e.printStackTrace();}
		        catch(TransformerException e){e.printStackTrace();}
		 }
		
}
